#include "Bot.h"


Bot::Bot()//PhysicComponent* phys, AIComponent* ai, GraphicsComponent* graph) : 
  //GameObject(mPhysics, mAI, mGraphics)
{
	mType = bot;
	mPhysics->getBody()->setPosition(core::vector3df(200, 0, 500));
	auto* steering = new PathFollowing();
	core::array<core::vector3df> list;
	list.push_back(core::vector3df(500.0f, 0.0f, 20.0f));
	steering->init(mAI->getVehicle(),list, true);
	mAI->setSteering(steering);
}


Bot::~Bot(void)
{

}
void Bot::update(float dt)
{
	core::vector3df oldPos = mPhysics->getBody()->getPosition();
	std::list<GameObject*> mListMember;
	mListMember = AutoList<GameObject>::GetAllMembers();
	for(std::list<GameObject*>::iterator i = mListMember.begin(); i != mListMember.end(); ++i)
	{
		EnforceNonPenetrationContraint(this, AutoList<GameObject>::GetAllMembers());
	//	if((*i) == this) continue;
	////	if(mPhysics->getBody()->getPosition().getLength() == core::vector3df(100.0f, 50.0f, 100.0f).getLength())
	//	{
	//		auto* steering = new Seek();
	//		steering->init(mPhysics->getBody(), core::vector3df(100, 50, 1000));
	//		mAI->setSteering(steering);
	//	}
	}
	
	mAI->update(dt);	
	const core::vector3df pos = mPhysics->getBody()->getPosition(); // + mPhysics->getBody()->getVelocity() * dt;
	mGraphics->getNode()->setPosition(pos);
	if(pos != oldPos)
		mGraphics->getNode()->setRotation((pos - oldPos).getHorizontalAngle());
	mGraphics->getNode()->updateAbsolutePosition();
	mGraphics->getAnimator()->setTargetNode(mGraphics->getNode());
}

